// pages/demo6/MulButton/MulButton.js
Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		hasDelete: {
			type: Boolean,
			value: true
		},
		type:{
			type: String,
			value: "option"
		},
		value:{
			type: String,
			value: ""
		},
		images:{
			type: Array,
			value: []
		}
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		isOpenImage: false,
		isOpenText: false
	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		imageTap: function(e){
			var _this = this;
			wx.chooseImage({
				success: function(res) {
					// console.log(res.tempFilePaths)
					var isOpenImage = true;
					var images = [..._this.data.images, ...res.tempFilePaths];
					_this.setData({
						isOpenImage, 
						images
					});
					_this.triggerEvent("images", {type: _this.data.type, images: images});
				},
			})

		},
		closeImage: function (e) {
			var isOpenImage = false;
			var images = [];
			this.setData({
				isOpenImage,
				images
			})
		},
		removeImage: function(e) {
			this.triggerEvent("deleteimg", {type: this.data.type, index: e.target.dataset.index});
		},
		textTap: function(e){
			var isOpenText = true;
			this.setData({
				isOpenText
			})
		},
		closeText: function(e){
			var isOpenText = false;
			//还应该清除文字
			this.setData({
				isOpenText
			})
		},
		input: function(e){
			this.triggerEvent("text", { type: this.data.type, text: e.detail.value });
		},
		deleteTap: function(e){
			this.triggerEvent("delete");
		}
	}
})
